<template>
  <div class="time-wrapper">
    <div class="time-inner">
      <div class="time-item start">
        <div class="date">{{ dateFilter(startTime) }}</div>
        <div class="time">{{ timeFilter(startTime) }}</div>
      </div>
      <div class="diff">
        <div class="diff-value" v-if="upper">{{ upper }}</div>
        <div class="diff-spliter"></div>
        <div class="diff-value" v-if="bottom">{{ bottom }}</div>
      </div>
      <div class="time-item end">
        <div class="date">{{ dateFilter(endTime) }}</div>
        <div class="time">{{ timeFilter(endTime) }}</div>
      </div>
    </div>
  </div>
</template>
<script>
import dayjs from "dayjs";
export default {
  data() {
    return {};
  },
  props: {
    startTime: String,
    endTime: String,
    upper: String,
    bottom: String,
  },
  emits: ["timeClick"],
  methods: {
    dateFilter(val) {
      return val ? dayjs(val).format("YYYY年M月D日") : '-';
    },
    timeFilter(val) {
      if (val) {
        const dayOfWeek = dayjs(val).day();
        const weeks = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
        const timeWeek = weeks[dayOfWeek];
        const hourTime = dayjs(val).format("HH:mm");
        // return `${timeWeek} ${hourTime}`;
        return `${hourTime}`;
      } else {
        return '-'
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.time-wrapper {
  .time-inner {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    position: relative;
    .time-item {
      color: #191c27ff;
      display: flex;
      flex-direction: column;
      flex-shrink: 0;
      font-size: 28rpx;
      font-weight: 600;
      width: 240rpx;
      .date {
        height: 44rpx;
        line-height: 44rpx;
        margin-bottom: 4rpx;
      }
      .time {
        height: 40rpx;
        line-height: 40rpx;
      }
      &.start {
        align-items: flex-start;
      }
      &.end {
        align-items: flex-end;
      }
    }
    .diff {
      display: flex;
      align-items: center;
      flex-direction: column;
      position: absolute;
      left: 50%;
      top: 16rpx;
      transform: translateX(-50%);
      .diff-value {
        margin: 0 16rpx;
        font-weight: 400;
        font-size: 24rpx;
        color: #1a1a1a;
        min-height: 28rpx;
        line-height: 28rpx;
        word-break: keep-all;
      }
      .diff-spliter {
        width: 124rpx;
        height: 2rpx;
        background: #e8e8e8;
        margin: 10rpx 0 8rpx;
      }
    }
  }
}
</style>
